home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
games
/
mdlv13.zip
/
MDLSRC.ZIP
/
BG_GRX.CC
next >
Wrap
C/C++ Source or Header
|
1996-07-09
|
35KB
|
1,255 lines
//
// this file by brian martin 1996
// brian@phyast.pitt.edu
//
// this is part of the source for the MedDLe quake model viewer/editor
//
// NOTE: much of this file comes from the great 3d tutorial 3gdpl.
// go get it and learn it.
// other stuff might be from the vga trainers
// some stuff is original
// It used to all be original, but I ran into some bugs so copied
// and pasted from everywhere. That means the zbuffer stuff is gone,
// but shaded texture mapping is here.
//
#include <dpmi.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>
#include<grdriver.h>
//#include<grx20.h>
#include"mdl.h"
#include<math.h>
#include<limits.h>
////grx stuff
GrFont *BG_Font;
GrContext *w1;
GrTextOption opt;
int G_start[1024]; /* polygon's */
int G_end[1024]; /* horizontal boundaries */
int G_miny,G_maxy; /* vertical boundaries */
#define G_P 10 /* fixed point math prcision */
#define G_LINEAR 32 /* linearely interpolate for */
signed_32_bit G_0_start[1024]; /* contains [32-G_P].[G_P] values */
signed_32_bit G_0_end[1024]; /* this thingie is to work faster */
signed_32_bit G_1_start[1024]; /* then multidimensional array */
signed_32_bit G_1_end[1024]; /* hope so, */
signed_32_bit G_2_start[1024];
signed_32_bit G_2_end[1024];
unsigned BG_ScreenWidth;
unsigned BG_ScreenHeight;
int BG_ClipXMin, BG_ClipYMin, BG_ClipXMax, BG_ClipYMax; // clipping
int BG_2DClipping; /* type of performed clipping */
int BG_TempMinY,BG_TempMaxY; /* vertical boundaries */
byte MDL_Font[354]=
{
0x00,0x00,0x00,0x00,0x00,0x00, 0x30,0x30,0x30,0x00,0x30,0x00,
0xd8,0x90,0x00,0x00,0x00,0x00, 0x6c,0xfe,0x6c,0xfe,0x6c,0x00,
0x7e,0xd0,0x7c,0x16,0xfc,0x00, 0xcc,0x18,0x30,0x60,0xcc,0x00,
0x60,0x90,0x74,0xd8,0x6c,0x00, 0x30,0x20,0x00,0x00,0x00,0x00,
0x60,0xc0,0xc0,0xc0,0x60,0x00, 0x18,0x0c,0x0c,0x0c,0x18,0x00,
0x6c,0x38,0xfe,0x38,0x6c,0x00, 0x00,0x30,0xfc,0x30,0x00,0x00,
0x00,0x00,0x00,0x30,0x20,0x00, 0x00,0x00,0x7c,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xc0,0x00, 0x0c,0x18,0x30,0x60,0xc0,0x00,
0x78,0x84,0x84,0x84,0x78,0x00, 0x04,0x0c,0x14,0x04,0x04,0x00,
0x78,0x84,0x18,0x20,0x7c,0x00, 0x78,0x04,0x38,0x04,0x78,0x00,
0x84,0x84,0xfc,0x04,0x04,0x00, 0xfc,0x80,0xf8,0x04,0xf8,0x00,
0x30,0x40,0xf8,0x84,0x78,0x00, 0xfc,0x04,0x08,0x10,0x10,0x00,
0x78,0x84,0x78,0x84,0x78,0x00, 0x78,0x84,0x7c,0x08,0x30,0x00,
0x00,0x30,0x00,0x30,0x00,0x00, 0x00,0x30,0x00,0x30,0x20,0x00,
0x30,0x60,0xc0,0x60,0x30,0x00, 0x00,0x7c,0x00,0x7c,0x00,0x00,
0x30,0x18,0x0c,0x18,0x30,0x00, 0x78,0xcc,0x18,0x00,0x18,0x00,
0x78,0xcc,0xdc,0xc0,0x7c,0x00, 0x30,0x48,0x84,0xfc,0x84,0x00,
0xf8,0x84,0xf8,0x84,0xf8,0x00, 0x7c,0x80,0x80,0x80,0x7c,0x00,
0xf8,0x84,0x84,0x84,0xf8,0x00, 0xfc,0x80,0xf0,0x80,0xfc,0x00,
0xfc,0x80,0xf0,0x80,0x80,0x00, 0x7c,0x80,0x84,0x84,0x7c,0x00,
0x84,0x84,0xfc,0x84,0x84,0x00, 0x10,0x10,0x10,0x10,0x10,0x00,
0x04,0x04,0x04,0x84,0x78,0x00, 0x84,0x88,0xf0,0x88,0x84,0x00,
0x80,0x80,0x80,0x80,0xfc,0x00, 0x82,0xc6,0xaa,0x92,0x82,0x00,
0x84,0xc4,0xa4,0x94,0x8c,0x00, 0x78,0x84,0x84,0x84,0x78,0x00,
0xf8,0x84,0xf8,0x80,0x80,0x00, 0x78,0x84,0x84,0x78,0x1c,0x00,
0xf8,0x84,0xf8,0x90,0x88,0x00, 0x7c,0x80,0x78,0x04,0xf8,0x00,
0xfe,0x10,0x10,0x10,0x10,0x00, 0x84,0x84,0x84,0x84,0x78,0x00,
0x84,0x84,0x84,0x48,0x30,0x00, 0x82,0x82,0x92,0xaa,0x44,0x00,
0x84,0x48,0x30,0x48,0x84,0x00, 0x88,0x88,0x50,0x20,0x20,0x00,
0xf8,0x10,0x20,0x40,0xf8,0x00
};
int BG_MaxX, BG_MaxY;
void BG_InitFonts(void);
#define BG_Z_MIN 10 /* where viewing plane is */
#define BG_Z_MAX 64000 /* where viewing plane is */
#define BG_RADS 40.7436654 /* pseudo-grads into rads */
#define BG_LOG_FOCUS 8 /* log perspective foreshortening */
#define G_LINEAR 32 /* linearely interpolate for */
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// turn off graphics mode
void BG_TextMode(void)
{
// GrDestroyContext(w1);
GrSetMode(GR_default_text);
// __dpmi_regs r;
// r.x.ax=0x0003;
// __dpmi_int(0x10, &r);
//delete G_start; /* polygon's */
//delete G_end; /* horizontal boundaries */
//delete G_0_start; /* contains [32-G_P].[G_P] values */
//delete G_0_end; /* this thingie is to work faster */
//delete G_1_start; /* then multidimensional array */
//delete G_1_end; /* hope so, */
//delete G_2_start;
//delete G_2_end;
}
//start graphics mode
void BG_GraphicsMode(char *drv, int a)
{
GrSetDriver(drv);
if(GrCurrentVideoDriver() == NULL)
{
printf("No graphics driver found\n");
exit(1);
}
switch(a)
{
case 0: GrSetMode(GR_width_height_color_graphics,320,200,256); break;
case 1: GrSetMode(GR_width_height_color_graphics,640,350,256); break;
case 2: GrSetMode(GR_width_height_color_graphics,640,480,256); break;
case 3: GrSetMode(GR_width_height_color_graphics,800,600,256); break;
case 4: GrSetMode(GR_width_height_color_graphics,1024,768,256); break;
exit(1);
}
BG_ScreenWidth = GrMaxX()+1;
BG_ScreenHeight = GrMaxY()+1;
BG_InitFonts();
BG_ClipXMin = 0;
BG_ClipYMin = 0;
BG_ClipXMax = BG_ScreenWidth-1;
BG_ClipYMax = BG_ScreenHeight-1;
}
//load in fonts
void BG_InitFonts(void)
{
BG_Font=GrLoadFont("mdl");
// LDVFont_big=GrLoadFont("helv38b");
// LDVFont_sym=GrLoadFont("symb16");
memset(&opt,0,sizeof(opt));
opt.txo_font = BG_Font;
opt.txo_xalign = GR_ALIGN_LEFT;
opt.txo_yalign = GR_ALIGN_TOP;
opt.txo_direct = GR_TEXT_RIGHT;
opt.txo_fgcolor.v = GrBlack();
opt.txo_bgcolor.v = 0;
return;
}
//draw text
void BG_Text(char *buff, int x, int y, int front, int back)
{
int l;
opt.txo_fgcolor.v = front;
opt.txo_bgcolor.v = back;
l=strlen(buff);
GrDrawString(buff,l,x,y,&opt);
return;
}
void MDL_Text(word x,word y,char *string,register unsigned char color)
{
int nm,i,j;
unsigned char cur;
unsigned char *adr,*l_adr;
adr=G_buffer+BG_ScreenWidth*y+x;
while(*string!='\0')
{
nm=((*string++)-' ');
if(nm>58) nm-=' ';
nm*=6;
for(i=0,l_adr=adr;i<6;i++,l_adr+=BG_ScreenWidth)
{
cur=MDL_Font[nm++];
for(j=0;j<8;j++)
if(cur&(0x80>>j)) *(l_adr+j)=color;
}
adr+=8; /* Next word */
}
}
void BG_ClearScreen(byte color)
{
GrClearScreen(color);
}
void BG_OpenPalette(char *palname, unsigned char *pal)
{
FILE *p;
int i,j;
char ch;
if((p=fopen(palname,"rt"))==NULL)
{
fprintf(stderr,"can't open %s ... exiting\n",palname);
exit(1);
}
while(fgetc(p)!=0x0A); // read some header
while(fgetc(p)!=0x0A); // smore header
while(fgetc(p)!=0x0A); // this line is for # colors (better be 256)
for(i=0;i<256;i++)
{
fscanf(p,"%d",&j); pal[i*3]=(unsigned char)j;
fscanf(p,"%d",&j); pal[i*3+1]=(unsigned char)j;
fscanf(p,"%d",&j); pal[i*3+2]=(unsigned char)j;
}
fclose(p);
}
void BG_PutPixel(word x, word y, byte c )
{
GrPlot(x,y,c);
}
void BG_Line(int x1, int y1, int x2, int y2, int c)
{
GrLine(x1,y1,x2,y2,c);
}
void BG_SetPalette(unsigned char *pal)
{
int i;
for(i=0;i<256;i++)
{
outportb(0x3c8,(byte)i);
outportb(0x3c9,(byte)pal[i*3]/4);
outportb(0x3c9,(byte)pal[i*3+1]/4);
outportb(0x3c9,(byte)pal[i*3+2]/4);
}
}
struct BMP_HEADER{
unsigned filesize;
short int reserved1;
short int reserved2;
int headersize;
int infosize;
int width;
int height;
short int planes;
short int b